<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 * Class UserFrom
 *
 * @package App\Model
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom query()
 * @property int $id
 * @property int $user_id 用户id
 * @property int $one_user_id 一级普通会员id
 * @property int $two_user_id 二级普通会员id
 * @property int $one_salesman_id 一级业务员id
 * @property int $two_salesman_id 二级业务员id
 * @property int $three_salesman_id 三级等以上业务员id
 * @property int $oprator_id 运营商id
 * @property int $place_partner_id 城市合伙人id
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 创建时间
 * @property string|null $deleted_at 删除时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereOneSalesmanId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereOneUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereOpratorId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom wherePlacePartnerId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereThreeSalesmanId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereTwoSalesmanId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereTwoUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserFrom whereUserId($value)
 */
class UserFrom extends Model
{
    protected  $table = 'user_from';

    protected  $fillable= ['user_id', 'one_user_id', 'two_user_id', 'one_salesman_id', 'two_salesman_id', 'three_salesman_id', 'oprator_id', 'place_partner_id'];

    // 直接推广人
    public function getUserDirectPromotersCommissionDetails()
    {
        return $this->hasMany(UserCommissionDetail::class, 'user_id', 'id')->where(['relation' => 1, 'relation_id' => 'salesman_id'])->where()->orderBy('create_at', 'asc');

    }

    // 间接推广人
    public function getUserIndirectPromotersCommissionDetails()
    {
        return $this->hasMany(UserCommissionDetail::class, 'user_id', 'id')->where(['relation' => 2, 'relation_id' => 'salesman_id'])->orderBy('create_at', 'asc');

    }
}
